home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_dos.lha / dos / srgpdemo / test_loc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-11-26  |  3.8 KB  |  154 lines

  1. /**
  2. See the README file for details on this demo's usage.
  3. **/
  4.  
  5.  
  6. #include "srgp.h"
  7.  
  8.  
  9. static deluxe_locator_measure dlm;
  10. static char buffer[100];
  11. static char kmstring[2];
  12. static deluxe_keyboard_measure dkm;
  13.  
  14. static int lineheight, textw, texta, textd;
  15.  
  16. static int timeout;
  17.  
  18. static int locatorMode = INACTIVE;
  19. static char *modeNames[] = {"unused", "INACTIVE", "SAMPLE", "EVENT"};
  20.  
  21. static int locatorButtonMask = LEFT_BUTTON_MASK;
  22.  
  23.  
  24. static void DisplayLocatorMeasure ()
  25. {
  26.    int y = 400;
  27.  
  28.    SRGP_setColor (COLOR_BLACK);
  29.    SRGP_fillRectangleCoord (0, (400-(7*lineheight)-textd), 1000, 400);
  30.  
  31.    SRGP_setColor (COLOR_WHITE);
  32.  
  33.    y -= lineheight;
  34.    sprintf (buffer, "LOCATOR MODE: %s", modeNames[locatorMode]);
  35.    SRGP_text (SRGP_defPoint(10,y), buffer);
  36.  
  37.    if (locatorMode == INACTIVE)
  38.       return;
  39.  
  40.    y -= lineheight;
  41.    sprintf (buffer, "Button mask: %s  %s  %s",
  42.         (locatorButtonMask&LEFT_BUTTON_MASK) == 0 ? "----" : "LEFT",
  43.         (locatorButtonMask&MIDDLE_BUTTON_MASK) == 0 ? "------" : "MIDDLE",
  44.         (locatorButtonMask&RIGHT_BUTTON_MASK) == 0 ? "-----" : "RIGHT");
  45.    SRGP_text (SRGP_defPoint(10,y), buffer);
  46.  
  47.    y -= lineheight;
  48.    sprintf (buffer, "Position: %3d, %3d", dlm.position.x, dlm.position.y);
  49.    SRGP_text (SRGP_defPoint(10,y), buffer);
  50.  
  51.    y -= lineheight;
  52.    sprintf (buffer, "Button chord: %d, %d, %d",
  53.         dlm.button_chord[0], dlm.button_chord[1], dlm.button_chord[2]);
  54.    SRGP_text (SRGP_defPoint(10,y), buffer);
  55.  
  56.    y -= lineheight;
  57.    sprintf (buffer, "Button of last transition: %d",
  58.         dlm.button_of_last_transition);
  59.    SRGP_text (SRGP_defPoint(10,y), buffer);
  60.  
  61.    y -= lineheight;
  62.    sprintf (buffer, "Modifier chord: %d, %d, %d",
  63.         dlm.modifier_chord[0], dlm.modifier_chord[1],
  64.         dlm.modifier_chord[2]);
  65.    SRGP_text (SRGP_defPoint(10,y), buffer);
  66.  
  67.    y -= lineheight;
  68.    sprintf (buffer, "Timestamp: %8d seconds, %2d ticks", 
  69.         dlm.timestamp.seconds, dlm.timestamp.ticks);
  70.    SRGP_text (SRGP_defPoint(10,y), buffer);
  71. }
  72.  
  73.  
  74.  
  75.  
  76.  
  77. main()
  78. {
  79.    SRGP_begin ("Test Locator", SCREEN_WIDTH, SCREEN_HEIGHT, 1, FALSE);
  80.  
  81.  
  82.    SRGP_setInputMode (KEYBOARD, EVENT);
  83.    SRGP_setKeyboardProcessingMode (RAW);
  84.  
  85.    dkm.buffer = kmstring;
  86.    dkm.buffer_length = 2;
  87.  
  88.    SRGP_inquireTextExtent ("Test", &textw, &texta, &textd);
  89.    lineheight = texta + textd;
  90.  
  91.    SRGP_setInputMode (LOCATOR, INACTIVE);
  92.    DisplayLocatorMeasure();
  93.  
  94.    while (1) {
  95.       timeout = (locatorMode == SAMPLE) ? 60 : -1;
  96.       switch (SRGP_waitEvent (timeout)) {
  97.        case NO_DEVICE:
  98.      SRGP_sampleDeluxeLocator (&dlm);
  99.      DisplayLocatorMeasure();
  100.      break;
  101.        case LOCATOR:
  102.      SRGP_getDeluxeLocator (&dlm);
  103.      DisplayLocatorMeasure();
  104.      break;
  105.        case KEYBOARD:
  106.      SRGP_getDeluxeKeyboard (&dkm);
  107.      switch (dkm.buffer[0]) {
  108.       case '1':
  109.         locatorButtonMask ^= LEFT_BUTTON_MASK;
  110.         SRGP_setLocatorButtonMask (locatorButtonMask);
  111.         DisplayLocatorMeasure();
  112.         break;
  113.       case '2':
  114.         locatorButtonMask ^= MIDDLE_BUTTON_MASK;
  115.         SRGP_setLocatorButtonMask (locatorButtonMask);
  116.         DisplayLocatorMeasure();
  117.         break;
  118.       case '3':
  119.         locatorButtonMask ^= RIGHT_BUTTON_MASK;
  120.         SRGP_setLocatorButtonMask (locatorButtonMask);
  121.         DisplayLocatorMeasure();
  122.         break;
  123.       case 'i': 
  124.         SRGP_setInputMode (LOCATOR, INACTIVE); 
  125.         locatorMode = INACTIVE;
  126.         DisplayLocatorMeasure();
  127.         break;
  128.       case 's': 
  129.         SRGP_setInputMode (LOCATOR, SAMPLE); 
  130.         locatorMode = SAMPLE;
  131.         DisplayLocatorMeasure();
  132.         break;
  133.       case 'e': 
  134.         SRGP_setInputMode (LOCATOR, EVENT);
  135.         locatorMode = EVENT;
  136.         DisplayLocatorMeasure();
  137.         break;
  138.       case 'c': 
  139.         SRGP_setLocatorEchoType (CURSOR);
  140.         break;
  141.       case 'l': 
  142.         SRGP_setLocatorEchoType (RUBBER_LINE);
  143.         break;
  144.       case 'r':                     
  145.         SRGP_setLocatorEchoType (RUBBER_RECT);
  146.         break;
  147.       case 'q': 
  148.         SRGP_end();
  149.         exit(0);
  150.      }
  151.       }
  152.    }
  153. }
  154.